'use strict';

module.exports = app => {
  const { STRING, INTEGER, TEXT } = app.Sequelize;

  const Category = app.model.define('category', {
    id: { type: INTEGER, primaryKey: true, autoIncrement: true },
    name: { type: STRING(50), allowNull: false, comment: '分类名称' },
    description: { type: TEXT, comment: '分类描述' },
    parentId: { type: INTEGER, defaultValue: 0, comment: '父分类ID，0表示顶级分类' },
    sort: { type: INTEGER, defaultValue: 0, comment: '排序' },
    status: { type: INTEGER, defaultValue: 1, comment: '状态：1-启用，0-禁用' }
  });
// 关联商品
  Category.associate = function() {
    app.model.Category.hasMany(app.model.Product, { foreignKey: 'categoryId', as: 'children' });
  }
  return Category;
};
